﻿namespace TowerofHanoi
{
    internal class Program
    {
        static void Hanoi(int n, string TowerA, string TowerB, string TowerC)
        {
            //退出递归条件
            if (n == 1)
            {
                Console.WriteLine($"将第{n}个盘子由塔{TowerA}移动到塔{TowerC}");
            }
            else
            {
                //将（n - 1)层由塔A经塔C移动到塔B
                Hanoi(n - 1, TowerA, TowerC, TowerB);
                Console.WriteLine($"将第{n}个盘子由塔{TowerA}移动到塔{TowerC}");              
                //将（n - 1)层由塔B移动到塔C
                Hanoi(n - 1, TowerB, TowerA, TowerC);               
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("请输入盘子个数：");
            int n = Convert.ToInt32(Console.ReadLine());
            Hanoi(n, "A", "B", "C");
        }
    }
}